#!/bin/bash
svr=UKing_LiveMTransServer
outputfilename=`date '+%Y%m%d%H%M%S'`.csv

echo "time,cpu,memory,fd" >> ${outputfilename}

ret=`ps -ef |grep -v grep|grep ${svr}  |awk '{print $2}'`
echo ${ret}

SELECTPID=0
for pid in ${ret}
do
	if [ "${SELECTPID}" -lt "${pid}" ];then
		SELECTPID=${pid}
	fi
done
echo "selectpid is ${SELECTPID}"
# 该脚本用于监控程序的内存,CPU和打开的文件数
while(true)
do
	echo `date '+%Y-%m-%d %H:%M:%S'` "," `top -n 1 -p ${SELECTPID} | grep ${SELECTPID} | awk '{print $10","$11}'` "," `ls -l /proc/${SELECTPID}/fd/ | wc -l`  >> ${outputfilename}
	sleep 5
done


